/**
 * @author: wq
 * @Date: 2017/5/3
 * @Time: 16:52
 * <p>
 * Description:
 *          ***
 */
import axios from 'axios';
import {API_NEW_VERSION} from '../api';
var qs = require('qs');
const ORDERS_RECEIVABLES = '/orders/receivable';
const ORDERS_RECEIVABLES_BY_INVOICE_NUMBER = '/orders/receivable/by_invoice_number';

/**
 * 获取应收单列表
 * @param params
 * @returns {AxiosPromise}
 */
export const getOrderReceivables = params => {
  return axios.get(API_NEW_VERSION + ORDERS_RECEIVABLES, {params: params});
};

/**
 * 获取没有出账单的应收单列表
 * @param params
 * @returns {AxiosPromise}
 */
export const getNotOutInvoiceOrderReceivables = params => {
  return axios.get(API_NEW_VERSION + ORDERS_RECEIVABLES_BY_INVOICE_NUMBER, {params: params});
};

/**
 * 保存应收单
 * @param params
 * @returns {AxiosPromise}
 */
export const saveOrderReceivable = params => {
  return axios.post(API_NEW_VERSION + ORDERS_RECEIVABLES, params);
};

/**
 * 删除应收单
 * @param id
 * @returns {AxiosPromise}
 */
export const deleteOrderReceivable = id => {
  return axios.delete(API_NEW_VERSION + ORDERS_RECEIVABLES + '/' + id);
};

/**
 * 应收统计列表
 * @param params
 * @returns {*}
 */
export const getOrderReceivableStatistics = params => {
  return axios.get(API_NEW_VERSION + 'orders/receivable/statistics', {params: params});
};

/**
 * 按月销账时，根据查询条件筛选应收统计列表
 * @param params
 */
export const getOrderReceivableStatisticsMonthly = params => {
  return axios.get(API_NEW_VERSION + 'orders/receivable/statistics/monthly', {params: params});
};

/**
 * 应收统计列表
 * @param params
 * @returns {*}
 */
export const saveOrderReceivableStatistics = params => {
  return axios.post(API_NEW_VERSION + 'orders/receivable/statistics', qs.stringify({json_model: params}));
};

/**
 * 按月销账，应收统计列表
 * @param params
 * @returns {*}
 */
export const saveOrderReceivableStatisticsMonthly = params => {
  return axios.post(API_NEW_VERSION + 'orders/receivable/statistics/account/monthly', qs.stringify({json_model: params}));
};

/**
 * 月账单，获取应收列表
 * @param params
 * @returns {AxiosPromise}
 */
export const getOrderReceivableStatisticsMonthlyBill = params => {
  return axios.get(API_NEW_VERSION + 'orders/receivable/statistics/monthly/byconfirmdate', {params: params});
};

export const getOrderReceivableStatisticsMonthlyBillBySign = params => {
  return axios.get(API_NEW_VERSION + 'orders/receivable/statistics/monthly/return_order', {params: params});
};

/**
 * 收取收款记录
 * @param params
 * @returns {*}
 */
export const getOrderPayStatistics = orderId => {
  return axios.get(API_NEW_VERSION + 'orders/pay/order_id/?order_id=' + orderId);
};
